//------------------------------------------------------------------------------------
#include "CControlPanel.h"
#include "CFont.h"
#include "common.h"
//------------------------------------------------------------------------------------
CControlPanel::CControlPanel(int nbVie) {
    controlPanel = QImage(":/snake/images/controlPanel.png");
	sol = QImage(":/snake/images/sol.png");
	
	this->nbVie = nbVie;
	nbSouris = 0;
	temps = 0;
	worldNum = 1;
}
//------------------------------------------------------------------------------------
void CControlPanel::draw(QPainter *painter) {
	int x, y;
	
	for(y=0;y<CELL_HEIGHT*INFO_HEIGHT;y+=CELL_HEIGHT) {
		for(x=0;x<MAP_WIDTH;x+=CELL_WIDTH) {
			painter->drawImage(QPoint(x, y), sol);
		}
	}

	painter->drawImage(QPoint(0, 0), controlPanel);

	drawValue(painter, worldNum, 109, 18);
	drawValue(painter, nbVie, 109, 34);
	drawValue(painter, nbSouris, 676, 18);
	drawValue(painter, temps, 676, 34);
}
//------------------------------------------------------------------------------------
void CControlPanel::setNbVie(int nbVie) {
	if(nbVie > 99) {
		nbVie = 99;
	}

	this->nbVie = nbVie;
}
//------------------------------------------------------------------------------------
void CControlPanel::drawValue(QPainter *painter, int value, int x, int y) {
	int digit;
	int newValue;
	CFont *font = CFont::getInstance();

	do {
		newValue = value / 10;
		digit = value - newValue * 10;
	
		font->draw(painter, digit, x, y);

		x-=FONT_WIDTH;
		value = newValue;			
	}while(value > 0);
}
//------------------------------------------------------------------------------------


